<template>
  <div id="wangeditor">
    <div ref="editorElem" style="text-align:left"></div>
  </div>
</template>
<script>
import E from "wangeditor"
export default {
  name: "editorElem",
  data() {
    return {
      editor: null,
      editorContent: "",
    }
  },
  props: ["editChange"], // 接收父组件的方法
  mounted() {
    this.editor = new E(this.$refs.editorElem)
    this.editor.config.onchange = newHtml => {
      // 发送给父元素
      this.$emit("editChange", newHtml)
    }
    this.editor.create() // 创建富文本实例
    if (!this.content) {
      this.editor.txt.html("请编辑内容1")
    }
  },
}
</script>
<style>
#wangeditor {
  width: 50rem;
}
</style>
